clear all
set more off
set scheme s2color
cd ""

use "sample.dta", clear
gen first_treat = 1 + (mdy(csm_month,csm_day,2020) - mdy(1,10,2020))

****************
* Subfigure (1)
****************

preserve

csdid in_confn14 if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"
gen faction = 1

tempfile in_confn14
save `in_confn14'

restore

preserve

csdid in_confn14 if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"

gen faction = 0
append using `in_confn14'

replace rel_time = rel_time - 0.1 if faction == 1
replace rel_time = rel_time + 0.1 if faction == 0
#delimit ;
twoway (scatter b rel_time if faction == 1, sort msymbol(Oh) mcolor(green) pstyle(p4))
       (scatter b rel_time if faction == 0, msymbol(Th) mcolor(orange) pstyle(p4))
       (rcap ul ll rel_time if faction == 1, lpattern(dash) lcolor(green))
       (rcap ul ll rel_time if faction == 0, lpattern(dash) lcolor(orange) lcolor(*0.9)),
        xtitle("Relative days to Community Stringent Measures") xlabel(-5(1)10, labsize(small) tlength(0.8))
        yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
        xline(-1, lcolor(cranberry) lwidth(thin) lpattern(dash))
        ylabel(, labsize(small) tlength(0.8) grid glwidth(vthin) nogextend)
        legend(order(1 "With informal tie" 2 "Without informal tie") position(8) ring(0) col(1))
        graphregion(fcolor(white) color(white) icolor(white) margin(small)) plotregion(margin(vsmall));
#delimit cr

restore

****************
* Subfigure (2)
****************

preserve

csdid d_movewithin if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"
gen faction = 1

tempfile d_movewithin
save `d_movewithin'

restore

preserve

csdid d_movewithin if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"

gen faction = 0
append using `d_movewithin'

replace rel_time = rel_time - 0.1 if faction == 1
replace rel_time = rel_time + 0.1 if faction == 0
#delimit ;
twoway (scatter b rel_time if faction == 1, sort msymbol(Oh) mcolor(green) pstyle(p4))
       (scatter b rel_time if faction == 0, msymbol(Th) mcolor(orange) pstyle(p4))
       (rcap ul ll rel_time if faction == 1, lpattern(dash) lcolor(green))
       (rcap ul ll rel_time if faction == 0, lpattern(dash) lcolor(orange) lcolor(*0.9)),
        xtitle("Relative days to Community Stringent Measures") xlabel(-5(1)10, labsize(small) tlength(0.8))
        yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
        xline(-1, lcolor(cranberry) lwidth(thin) lpattern(dash))
        ylabel(, labsize(small) tlength(0.8) grid glwidth(vthin) nogextend)
        legend(order(1 "With informal tie" 2 "Without informal tie") position(8) ring(0) col(1))
        graphregion(fcolor(white) color(white) icolor(white) margin(small)) plotregion(margin(vsmall));
#delimit cr

restore

****************
* Subfigure (3)
****************

preserve

csdid bdindexS7_std if faction == 1, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"
gen faction = 1

tempfile bdindexS7_std
save `bdindexS7_std'

restore

preserve

csdid bdindexS7_std if faction == 0, ivar(city_code) time(time) gvar(first_treat) agg(event) long2 wboot rseed(10101) pointwise
do "figureA14_graph.do"

gen faction = 0
append using `bdindexS7_std'

replace rel_time = rel_time - 0.1 if faction == 1
replace rel_time = rel_time + 0.1 if faction == 0
#delimit ;
twoway (scatter b rel_time if faction == 1, sort msymbol(Oh) mcolor(green) pstyle(p4))
       (scatter b rel_time if faction == 0, msymbol(Th) mcolor(orange) pstyle(p4))
       (rcap ul ll rel_time if faction == 1, lpattern(dash) lcolor(green))
       (rcap ul ll rel_time if faction == 0, lpattern(dash) lcolor(orange) lcolor(*0.9)),
        xtitle("Relative days to Community Stringent Measures") xlabel(-5(1)10, labsize(small) tlength(0.8))
        yline(0 , lcolor(cranberry) lwidth(thin) lpattern(dash))
        xline(-1, lcolor(cranberry) lwidth(thin) lpattern(dash))
        ylabel(, labsize(small) tlength(0.8) grid glwidth(vthin) nogextend)
        legend(order(1 "With informal tie" 2 "Without informal tie") position(11) ring(0) col(1))
        graphregion(fcolor(white) color(white) icolor(white) margin(small)) plotregion(margin(vsmall));
#delimit cr

restore